

package com.dog.basics.admin.controller.common;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.dog.basics.bean.dto.admin.common.AdminSysConfigAddDto;
import com.dog.basics.bean.dto.admin.common.AdminSysConfigEditDto;
import com.dog.basics.bean.dto.admin.common.AdminSysConfigFromDto;
import com.dog.basics.bean.vo.admin.common.AdminSysConfigVo;
import com.dog.basics.common.annotation.SysLog;
import com.dog.basics.common.util.PageParam;
import com.dog.basics.common.util.R;
import com.dog.basics.service.common.SysConfigService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;


/**
 * 参数配置
 *
 * @author cy code generator
 * @date 2021-03-18 09:56:14
 */
@RestController
@AllArgsConstructor
@RequestMapping("/admin/sysconfig")
@Api(value = "参数配置管理", tags = "参数配置管理")
public class SysConfigController {

    private final SysConfigService sysConfigService;

    /**
     * 分页查询
     *
     * @param page 分页对象
     * @param obj  参数配置
     * @return
     */
    @ApiOperation(value = "分页查询", notes = "admin_sysconfig_view")
    @GetMapping("/page")
    //@WordFilterCheck
    @PreAuthorize("@pms.hasPermission('admin_sysconfig_view')")
    public R<IPage<AdminSysConfigVo>> getSysConfigPage(PageParam page, AdminSysConfigFromDto obj) {
        return R.ok(sysConfigService.getAdminPageList(page, obj));
    }


    /**
     * 通过id查询参数配置
     *
     * @param id id
     * @return R
     */
    @ApiOperation(value = "通过id查询", notes = "admin_sysconfig_info")
    @GetMapping("/{id}")
    @PreAuthorize("@pms.hasPermission('admin_sysconfig_info')")
    public R<AdminSysConfigVo> getById(@PathVariable("id") Long id) {
        return R.ok(sysConfigService.getAdminObjXq(id));
    }

    /**
     * 新增参数配置
     *
     * @param obj 参数配置
     * @return R
     */
    @ApiOperation(value = "新增参数配置", notes = "admin_sysconfig_add")
    @SysLog("新增参数配置")
    @PostMapping
    @PreAuthorize("@pms.hasPermission('admin_sysconfig_add')")
    public R<Boolean> save(@Valid @RequestBody AdminSysConfigAddDto obj) {
        return R.ok(sysConfigService.saveAdminObj(obj));
    }

    /**
     * 修改参数配置
     *
     * @param obj 参数配置
     * @return R
     */
    @ApiOperation(value = "修改参数配置", notes = "admin_sysconfig_edit")
    @SysLog("修改参数配置")
    @PutMapping
    @PreAuthorize("@pms.hasPermission('admin_sysconfig_edit')")
    public R<Boolean> updateById(@Valid @RequestBody AdminSysConfigEditDto obj) {
        return R.ok(sysConfigService.editAdminObj(obj));
    }

    /**
     * 通过id删除参数配置
     *
     * @param id id
     * @return R
     */
    @ApiOperation(value = "通过id删除参数配置", notes = "admin_sysconfig_del")
    @SysLog("通过id删除参数配置")
    @DeleteMapping("/{id}")
    @ApiImplicitParam(name = "userId", value = "主键", required = true, dataType = "Long")
    @PreAuthorize("@pms.hasPermission('admin_sysconfig_del')")
    public R<Boolean> removeById(@PathVariable Long id) {
        return R.ok(sysConfigService.deleteObj(id));
    }

}
